{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "21ca37c4-a34d-43dc-aa5e-3873ecf487a3",
   "metadata": {},
   "source": [
    "# Downloader"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c4844e47-8948-4351-9cb2-572a2a975cd5",
   "metadata": {},
   "source": [
    "## 下载alos30数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "564cd275-603a-49df-972a-bf83784f7326",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from hydrodata.downloader.dem import Alos_DEM\n",
    "dem = Alos_DEM()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d388719e-5ad0-4216-9963-0fc156868d27",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'microsoft': {'url': 'https://planetarycomputer.microsoft.com/api/stac/v1/',\n",
       "  'collection_name': 'alos-dem'}}"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dem.list_sources()   # 查看stac源"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d8af8426-2ff8-4b55-ae07-1b7e4ee9e25c",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'gee': {'url': 'https://storage.googleapis.com/earthengine-stac/catalog/JAXA/catalog.json',\n",
       "  'collection_name': 'JAXA_ALOS_AW3D30_V3_2'}}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "source_name = 'gee'\n",
    "url = 'https://storage.googleapis.com/earthengine-stac/catalog/JAXA/catalog.json'\n",
    "collection_name = 'JAXA_ALOS_AW3D30_V3_2'\n",
    "dem.add_source(source_name=source_name, url=url, collection_name=collection_name)  # 自定义stac源"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "34847537-43e3-42fb-99ca-e716819af3d5",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'microsoft': {'url': 'https://planetarycomputer.microsoft.com/api/stac/v1/',\n",
       "  'collection_name': 'alos-dem'},\n",
       " 'gee': {'url': 'https://storage.googleapis.com/earthengine-stac/catalog/JAXA/catalog.json',\n",
       "  'collection_name': 'JAXA_ALOS_AW3D30_V3_2'}}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dem.list_sources()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "62d15dd7-bc0b-4fc3-b608-b41b7af3c6ff",
   "metadata": {},
   "source": [
    "通过四至范围获取dem链接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "79c76b29-db51-40d4-b3ad-200e2679e6ea",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['https://ai4edataeuwest.blob.core.windows.net/alos-dem/AW3D30_global/ALPSMLC30_N039E121_DSM.tif',\n",
       " 'https://ai4edataeuwest.blob.core.windows.net/alos-dem/AW3D30_global/ALPSMLC30_N038E121_DSM.tif',\n",
       " 'https://ai4edataeuwest.blob.core.windows.net/alos-dem/AW3D30_global/ALPSMLC30_N038E120_DSM.tif',\n",
       " 'https://ai4edataeuwest.blob.core.windows.net/alos-dem/AW3D30_global/ALPSMLC30_N037E121_DSM.tif',\n",
       " 'https://ai4edataeuwest.blob.core.windows.net/alos-dem/AW3D30_global/ALPSMLC30_N037E120_DSM.tif']"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hrefs = dem.search(bbox=[121,38,121.5,39])\n",
    "hrefs"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6fa9d135-07bf-4c2b-ba1f-af8c153c3b02",
   "metadata": {},
   "source": [
    "## 下载nfs数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "6c3e1611-9547-4c48-9bcc-2d216648510e",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from hydrodata.downloader import ncep_gfs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "d69aeaa8-985e-4df8-94b6-ac2ce2faf116",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "下载文件 ./gfs20230825.t06z.pgrb2.0p25.f120: 99806it [00:00, 224518.59it/s]\n"
     ]
    }
   ],
   "source": [
    "# 通过日期、时间、预测序列及范围下载10天内的gfs数据\n",
    "ncep_gfs.get_gfs_from_ncep(date='20230825',creation_time='06',forecast_time=120,bbox=[115,38,136,54])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python (stac-download)",
   "language": "python",
   "name": "stac-test"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
